package org.leetcode.easy.leetcode108;

import org.leetcode.TreeNode;

public class Solution {
    public TreeNode sortedArrayToBST(int[] nums) {

        return helper(nums,0, nums.length-1);
    }



    private TreeNode makeTree(int [] nums ,int left,int right){
        if (left>right){
            return null;
        }

        int mid =(left+right)>>>1;

        TreeNode root = new TreeNode(nums[mid]);

        root.left = makeTree(nums,left,mid-1);
        root.right = makeTree(nums,mid+1,right);

        return root;
    }


    private TreeNode helper(int [] nums,int left,int right){

        if (left>right){
            return null;
        }

        int mid =(left+right)/2;

        TreeNode node = new TreeNode(nums[mid]);

        node.left=helper(nums,left,mid-1);
        node.right=helper(nums,mid+1,right);
        return node;

    }






}
